package com.itheima.web.controller;

import cn.hutool.captcha.LineCaptcha;
import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Path;
import java.io.IOException;

@RestController
public class UserController {

    @Autowired
    private UserManager userManager;
    //用户数据翻页
    @GetMapping("/manage/users")
    public ResponseEntity findUsersByPage(
           @RequestParam(defaultValue = "1") Integer page,
           @RequestParam(defaultValue = "10")  Integer pagesize
    ) throws IOException {
        return  userManager.findUsersByPage(page , pagesize);
    }

    //用户基本资料
    @GetMapping("/manage/users/{userId}")
    public ResponseEntity findUserInfoById(
          @PathVariable Long userId
    ) throws IOException {
        return  userManager.findUserInfoById(userId);
    }


    //消息翻页
    @GetMapping("/manage/messages")
    public ResponseEntity findMessages(
            Long uid  , Integer state,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10")  Integer pagesize
    ) throws IOException {
        return  userManager.findMessages(uid , state , page ,pagesize);
    }
    //消息详情
    @GetMapping("/manage/messages/{movementId}")
    public ResponseEntity findMessageById(
            @PathVariable String movementId
    ) throws IOException {
        return  userManager.findMessageById(movementId);
    }

    //评论列表翻页
    @GetMapping("/manage/messages/comments")
    public ResponseEntity findCommentById(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10")  Integer pagesize,
            String messageID
    ) throws IOException {
        return  userManager.findCommentById(page ,pagesize ,messageID);
    }
}
